package com.cr.admin.business.vehicle.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.cr.admin.business.topic.pojo.entity.Topic;
import com.cr.admin.business.topic.pojo.param.TopicAddParam;
import com.cr.admin.business.topic.pojo.param.TopicUpdateParam;
import com.cr.admin.business.topic.pojo.query.TopicQuery;
import com.cr.admin.business.topic.service.TopicService;
import com.cr.admin.business.vehicle.pojo.entity.Vehicle;
import com.cr.admin.business.vehicle.pojo.param.VehicleAddParam;
import com.cr.admin.business.vehicle.pojo.param.VehicleUpdateParam;
import com.cr.admin.business.vehicle.pojo.query.VehicleQuery;
import com.cr.admin.business.vehicle.pojo.vo.VehicleVO;
import com.cr.admin.business.vehicle.service.VehicleService;
import com.cr.admin.system.pojo.entity.SysRole;
import com.cr.admin.system.pojo.vo.SysUserDetailVO;
import com.cr.common.response.JsonResult;
import com.cr.common.response.PageData;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@Api(tags = "90.车辆管理")
@RequestMapping("/api/bus/vehicle")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

//    @SaCheckPermission("bus:vehicle:query")
    @ApiOperation(value = "查询车辆列表")
    @GetMapping
    public JsonResult list(VehicleQuery vehicleQuery) {
        PageData<Vehicle> pageData = PageData.page(vehicleQuery.getPageNum(), vehicleQuery.getPageSize(), () -> vehicleService.list(vehicleQuery));
        System.out.println(pageData);
        return JsonResult.success(pageData);
    }

//    @SaCheckPermission("bus:vehicle:add")
    @ApiOperation(value = "新增车辆")
    @PostMapping
    public JsonResult insert(@Validated @RequestBody VehicleAddParam vehicleAddParam) {
        vehicleService.insert(vehicleAddParam);
        return JsonResult.success();
    }

    //@SaCheckPermission("bus:vehicle:edit")
    @ApiOperation(value = "修改车辆")
    @PutMapping
    public JsonResult update(@Validated @RequestBody VehicleUpdateParam vehicleUpdateParam) {
        vehicleService.updateById(vehicleUpdateParam);
        return JsonResult.success();
    }
//    @SaCheckPermission("bus:vehicle:del")
    @ApiOperation(value = "删除车辆")
    @DeleteMapping()
    public JsonResult delete(@RequestParam(name = "ids") List<Long> ids){
        vehicleService.deleteByIds(ids);
        return JsonResult.success();
    }
    //@SaCheckPermission("bus:vehicle:query")
    @ApiOperation(value = "查询车辆详情")
    @GetMapping("/{id}")
    public JsonResult getDetail(@PathVariable("id") Long id) {
        VehicleVO vehicleVO = vehicleService.selectById(id);
        return JsonResult.success(vehicleVO);
    }
    @ApiOperation(value = "查询全部车辆")
    @GetMapping("/all")
    public JsonResult all() {
        List<Vehicle> list = vehicleService.selectList(null);
        return JsonResult.success(list);
    }

}
